<template>
  <div>
    <el-table :data="categorylist">
      <el-table-column prop="_id" label="ID" width="220"></el-table-column>
      <el-table-column prop="name" label="广告名称" ></el-table-column>
      <el-table-column prop="items.url" label="广告地址" ></el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        width="180">
        <template slot-scope="scope">
          <el-button @click="$router.push(`edit/${scope.row._id}`)" type="text" size="small">编辑</el-button>
          <el-button @click="removeList(scope.row)" type="text" size="small">删除</el-button>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="address" label="地址">
      </el-table-column> -->
    </el-table>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        categorylist:[]
      }
    },
    created() {
      this.feach()
    },
    methods: {
      async feach(){
        let res = await this.$http.get('/rest/ads')
        this.categorylist=res.data
      },
      async removeList(row){
        this.$confirm(`是否确定要删除分类"${row.name}"`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http.delete(`/rest/ads/${row._id}`).then(res=>{
            console.log(res.status);
            this.feach()
          })
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
        
      },
    },
  }
</script>

<style lang="scss" scoped>

</style>